package com.burgeon.backend.Rest.Tags;
/**
 * 查询标签id通过vid
 */


import com.burgeon.backend.Rest.base.RESTBase;
import com.burgeon.backend.entity.VipTags;
import org.json.JSONArray;
import org.springframework.util.MultiValueMap;

import java.util.ArrayList;
import java.util.HashMap;

public class FindTagsIdByVip extends RESTBase {

    private String ip;
    private String account;
    private String password;

    public FindTagsIdByVip(String ip, String account, String password) {
        this.ip = ip;
        this.account = account;
        this.password = password;
    }

    /**
     * 发送并接收字符创
     */

    public String getData(String phone) throws Exception {
        String url = "http://" + ip + "/servlets/binserv/Rest";

        String str = RESULT(Data(phone), url);

        String code = new JSONArray(str).getJSONObject(0).getString("code");

        if (!"0".equals(code)) {
            throw new Exception("获取数据错误");
        }
        String count = new JSONArray(str).getJSONObject(0).getString("count");
        if (!"1".equals(count)) {
            throw new Exception("获取数据错误");
        }
        JSONArray jsonArray = new JSONArray(str).getJSONObject(0).getJSONArray("rows");

        return jsonArray.getJSONArray(0).getString(0);
    }

    private MultiValueMap Data(String phone) {
        HashMap params = new HashMap();
        ArrayList columns = new ArrayList();//查询字段
        columns.add("ID");

        params.put("columns", columns);
        params.put("table", "C_VIPATTRIB");//表名

        params.put("count", "true");

        HashMap paramss = new HashMap();
        String ac = "'" + phone + "'";
        paramss.put("column", "'C_VIP_ID;CARDNO'");
        paramss.put("condition", ac);
        params.put("params", paramss);

        return DATA("Query", params, account, password);
    }

    public static void main(String[] args) {
        FindTagsIdByVip g = new FindTagsIdByVip("59.110.28.94:90", "nea@burgeon.com.cn", "burgeon55321");
        try {
            System.err.println(g.getData("17732141036"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
